home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Reference Guide
/
C-C++ Interactive Reference Guide.iso
/
c_ref
/
csource5
/
357_01
/
cstar1.exe
/
STRIP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-18
|
2KB
|
100 lines
/*
Program to strip extra '\r' characters from a file.
PUBLIC DOMAIN SOFTWARE
This program was placed in the public domain on June 15, 1991,
by its author and sole owner,
Edward K. Ream
1617 Monroe Street
Madison, WI 53711
(608) 257-0802
This program may be used for any commercial or non-commercial purpose.
DISCLAIMER OF WARRANTIES
Edward K. Ream (Ream) specifically disclaims all warranties,
expressed or implied, with respect to this computer software,
including but not limited to implied warranties of merchantability
and fitness for a particular purpose. In no event shall Ream be
liable for any loss of profit or any commercial damage, including
but not limited to special, incidental consequential or other damages.
*/
#include <stdio.h>
#include <stdlib.h>
main(argc, argv)
int argc;
char **argv;
{
char *in = NULL, *out = NULL, *arg;
FILE * in_file, *out_file;
printf("strip: March 8, 1989\n");
if (argc < 3) {
printf("strip in out\n");
exit(0);
}
/* Process all the arguments on the command line. */
argc--;
argv++;
while (argc-- > 0) {
arg = *argv++;
if (in == NULL) {
in = arg;
}
else if (out == NULL) {
out = arg;
}
else {
printf("Extra file argument: %s\n", arg);
exit(0);
}
}
/* Make sure that both file arguments were provided. */
if (in == NULL) {
printf("Missing input, output file arguments.\n");
exit(0);
}
else if (out == NULL) {
printf("Missing output file argument.\n");
exit(0);
}
/* Open the files. */
in_file = fopen(in, "r");
if (in_file == NULL) {
printf("Can not open %s\n", in);
exit(0);
}
out_file = fopen(out, "w");
if (out_file == NULL) {
printf("Can not create %s\n", out);
exit(0);
}
/* Copy the file. */
for(;;) {
int c;
c = fgetc(in_file);
if (c == EOF) {
break;
}
else if (c == '\r') {
continue;
}
else {
fputc(c, out_file);
}
}
fclose(in_file);
fclose(out_file);
}